import random

from pynput import keyboard
from playsound import playsound
from threading import Thread

sound_list = ["sound\\2.mp3", "sound\\3.mp3", "sound\\4.mp3"]

count = 0


def on_rel(key):
    """key: 用户按了哪个键"""
    """callback"""
    print(key)
    global count
    count += 1
    if count % 10 == 0:
        i = random.randint(0, len(sound_list)-1)
        # playsound(sound_list[i])
        t = Thread(target=playsound, args=(sound_list[i], ))
        t.start()



# Listener 捕捉键盘按键
listener = keyboard.Listener(on_release=on_rel)
listener.start()
listener.join()

